class InstructionAnalysis:
    """
    存储寄存器号到寄存器ABI名的映射
    """
    index2RegABIName = {
        0: "zero",  # 0
        1: "ra",
        2: "sp",
        3: "gp",
        4: "tp",
        5: "t0",
        6: "t1",
        7: "t2",
        8: ["s0", "fp"],
        9: "s1",
        10: "a0",
        11: "a1",
        12: "a2",
        13: "a3",
        14: "a4",
        15: "a5",
        16: "a6",
        17: "a7",
        18: "s2",
        19: "s3",
        20: "s4",
        21: "s5",
        22: "s6",
        23: "s7",
        24: "s8",
        25: "s9",
        26: "s10",
        27: "s11",
        28: "t3",
        29: "t4",
        30: "t5",
        31: "t6",
        32: "t7",
    }

    """
    存储寄存器号到寄存器名的映射
    """
    index2RegName = {
        0: "x0",
        1: "x1",
        2: "x2",
        3: "x3",
        4: "x4",
        5: "x5",
        6: "x6",
        7: "x7",
        8: "x8",
        9: "x9",
        10: "x10",
        11: "x11",
        12: "x12",
        13: "x13",
        14: "x14",
        15: "x15",
        16: "x16",
        17: "x17",
        18: "x18",
        19: "x19",
        20: "x20",
        21: "x21",
        22: "x22",
        23: "x23",
        24: "x24",
        25: "x25",
        26: "x26",
        27: "x27",
        28: "x28",
        29: "x29",
        30: "x30",
        31: "x31",
        32: "x32",
    }

    instructionOpcode = ['fld', 'fsd', 'fadd.d', 'addi', 'bne']

    instructionOpcode3 = ['fld', 'fsd']

    latenceSet = {'fld': {'fsd': 0,
                          'fadd.d': 1},
                  'fsd': 0,
                  'fadd.d': {'fadd.d': 3,
                             'fsd': 2},
                  'bne': 1,
                  'addi': 1
                  }

    def __init__(self):
        self.regName = [k for k, v in self.reverse_dict(self.index2RegName).items()]
        self.regABIName = [k for k, v in self.reverse_dict(self.index2RegABIName).items()]
    pass

    def reverse_dict(self, d):
        """
        字典key, value值互换函数
        """
        reverse_d = {}
        for k, v in d.items():
            if isinstance(v, list):
                for temp in v:
                    reverse_d[temp] = k
            else:
                reverse_d[v] = k
        return reverse_d

    def instructionSplit(self, ist):
        # print(str(ist).strip().replace(", ", ",").replace(" ,", ","))
        return str(ist).strip().replace(", ", ",").replace(" ,", ",").replace('(', " ").replace(")", " ").replace(",", " ").split(" ")

